package com.hc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.domain.Tag;
import com.hc.dto.ListTagDTO;
import com.hc.mapper.TagMapper;
import com.hc.service.TagService;
import com.hc.vo.TagVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 标签
 *
 * @author 梁云亮
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {
    @Resource
    private TagMapper tagMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int createTag(TagVO tagVO) {
        int insertRes = tagMapper.insertTag(tagVO);
        return insertRes;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int batchCreateTags(List<TagVO> tagVOS) {
        int res = tagMapper.batchInsertTags(tagVOS);
        return res;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteTagById(int tagId) {
        int res = tagMapper.deleteById(tagId);
        return res;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int batchDeleteTagsById(List<Integer> ids) {
        int res = tagMapper.batchDeleteTagsById(ids);
        return res;
    }

    @Override
    public List<ListTagDTO> listTagsByBlogId(Integer blogId) {
        List<ListTagDTO> res = tagMapper.selectTagsByBlogId(blogId);
        return res;
    }

}
